/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de La Frontera
 * License Type: Academic
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class PagoDAO {
	public static Pago loadPagoByORMID(int pago_ID) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadPagoByORMID(session, pago_ID);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago getPagoByORMID(int pago_ID) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return getPagoByORMID(session, pago_ID);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByORMID(int pago_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadPagoByORMID(session, pago_ID, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago getPagoByORMID(int pago_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return getPagoByORMID(session, pago_ID, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByORMID(PersistentSession session, int pago_ID) throws PersistentException {
		try {
			return (Pago) session.load(orm.Pago.class, new Integer(pago_ID));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago getPagoByORMID(PersistentSession session, int pago_ID) throws PersistentException {
		try {
			return (Pago) session.get(orm.Pago.class, new Integer(pago_ID));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByORMID(PersistentSession session, int pago_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pago) session.load(orm.Pago.class, new Integer(pago_ID), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago getPagoByORMID(PersistentSession session, int pago_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pago) session.get(orm.Pago.class, new Integer(pago_ID), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryPago(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return queryPago(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryPago(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return queryPago(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago[] listPagoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return listPagoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago[] listPagoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return listPagoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryPago(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pago as Pago");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryPago(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pago as Pago");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago[] listPagoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		try {
			List list = queryPago(session, condition, orderBy);
			return (Pago[]) list.toArray(new Pago[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago[] listPagoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryPago(session, condition, orderBy, lockMode);
			return (Pago[]) list.toArray(new Pago[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadPagoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadPagoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Pago[] pagos = listPagoByQuery(session, condition, orderBy);
		if (pagos != null && pagos.length > 0)
			return pagos[0];
		else
			return null;
	}
	
	public static Pago loadPagoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Pago[] pagos = listPagoByQuery(session, condition, orderBy, lockMode);
		if (pagos != null && pagos.length > 0)
			return pagos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePagoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return iteratePagoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePagoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return iteratePagoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePagoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pago as Pago");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePagoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pago as Pago");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago createPago() {
		return new orm.Pago();
	}
	
	public static boolean save(orm.Pago pago) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().saveObject(pago);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.Pago pago) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().deleteObject(pago);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Pago pago)throws PersistentException {
		try {
			if(pago.getCuentacuenta() != null) {
				pago.getCuentacuenta().pago.remove(pago);
			}
			
			return delete(pago);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Pago pago, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(pago.getCuentacuenta() != null) {
				pago.getCuentacuenta().pago.remove(pago);
			}
			
			try {
				session.delete(pago);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.Pago pago) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().getSession().refresh(pago);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.Pago pago) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().getSession().evict(pago);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pago loadPagoByCriteria(PagoCriteria pagoCriteria) {
		Pago[] pagos = listPagoByCriteria(pagoCriteria);
		if(pagos == null || pagos.length == 0) {
			return null;
		}
		return pagos[0];
	}
	
	public static Pago[] listPagoByCriteria(PagoCriteria pagoCriteria) {
		return pagoCriteria.listPago();
	}
}
